package com.wbao.dianniu.manager;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.StringEntity;

import android.content.Context;

import com.wbao.dianniu.http.Batch;
import com.wbao.dianniu.http.Command;
import com.wbao.dianniu.http.HttpUtil;
import com.wbao.dianniu.http.HttpUtil.MyResponse;
import com.wbao.dianniu.listener.IRecruitStatus;
import com.wbao.dianniu.listener.IRecruitStatusListener;
import com.wbao.dianniu.logical.Action;
import com.wbao.dianniu.logical.GlobalContext;

/**
 * 	简历显示/隐藏
 * 
 * @author yejianjun
 *
 */
public class RecruitStatusManager implements IRecruitStatus {

	private IRecruitStatusListener mListener;
	private Context mContext;
	
	public RecruitStatusManager(Context context) {
		mContext = context;
	}
	
	@Override
	public void recruitStatus(int accountId, int recruitId, int status) {
		// TODO Auto-generated method stub
		StringEntity stringEntity = null;
		try {
			Batch batch = new Batch();
			batch.setToken(GlobalContext.token);
			Command command = new Command();
			command.addAction(Action.ACCOUNT_RECRUIT_STATUS)
					.addArgs("accountId", accountId)
					.addArgs("recruitId", recruitId)
					.addArgs("status", status);
			batch.addCommand(command);
			stringEntity = new StringEntity(batch.toJson(), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		HttpUtil http = new HttpUtil();
		http.req(mContext, stringEntity, new MyResponse() {

			@Override
			public void responseSucess(Object obj) {
				if (null != mListener)
					mListener.onRecruitStatusSuccess();
			}

			@Override
			public void responseFailure(String msg) {
				if (null != mListener)
					mListener.onRecruitStatusFailure(0, msg);
			}
		});
	}

	@Override
	public boolean addRecruitStatusListener(IRecruitStatusListener listener) {
		mListener = listener;
		return mListener == null ? false : true;
	}

	@Override
	public boolean removeRecruitStatusListener(IRecruitStatusListener listener) {
		if (null == listener)
			return false;
		mListener = null;
		return true;
	}

}
